#include "GL/glew.h"
#include "LoadShader.h"
#include "utility.h"
#include "vmath.h"

GLuint program, vao, vbo;

GLfloat vert[] = { 0.9f, 0.9f,  -0.9f, -0.9f,   0.9f, -0.9f,  0.9f, 0.9f,  -0.9f, -0.9f,   -0.9f, 0.9f };

bool init()
{
	ShaderInfo si[] = { { GL_VERTEX_SHADER, "Shader.vert" },{ GL_FRAGMENT_SHADER, "Shader.frag" },{ GL_NONE, nullptr } };
	program = LoadShade(si);

	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vert), vert, GL_STATIC_DRAW);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
	glEnableVertexAttribArray(0);

	glClearColor(0.0f, 0.05f, 0.05f, 1.0f);
	glUseProgram(program);
	return true;
}

void Display(double time)
{
	glClear(GL_COLOR_BUFFER_BIT);

	Matrix4f m;
	m = m * Matrix4f::createScale(0.5, 0.5, 0.5);
	glUniformMatrix4fv(1, 1, GL_FALSE, (float*)m);

	

	glBindVertexArray(vao);
	// glPointSize(10);
	// glLineWidth(5);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glUniform4f(100, 0.0f, 1.0f, 1.0f, 1.0f);
	glDrawArrays(GL_TRIANGLES, 0, 6);


	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glUniform4f(100, 0.8f, 0.6f, 0.6f, 1.0f);
	glLineWidth(4);
	glDrawArrays(GL_TRIANGLES, 0, 6);


}

void onClose()
{
	glDeleteVertexArrays(1, &vao);
	glDeleteBuffers(1, &vbo);
}

